﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HetmansProblem
{
    /// <summary>
    /// Main class of program logic
    /// </summary>
    class HetmansMain
    {
        Board board = new Board();

        internal Board Board
        {
            get { return board; }
            set { board = value; }
        }
        /// <summary>
        /// Main method. All logic of program
        /// </summary>
        public void Play()
        {
            
            List<List<string>> _tmpBoardTable = new List<List<string>>();//board for store temporary hetman and his moves 
            for (int i = 0; i < 8; i++)
            {
                _tmpBoardTable.Add(new List<string>());
                for (int j = 0; j < 8; j++)
                {
                    _tmpBoardTable[i].Add("O");
                }
            }
            do
            {
                Coordinate _freeField = board.FindFreeField();
                if (_freeField.x==-1)
                {
                    break;
                }
                DoPossibleMoves(_freeField, _tmpBoardTable);
                if (board.IsSafe(_freeField, _tmpBoardTable))
                {
                    board.PutH(_freeField);
                    board.PutPossibleMoves(_freeField,_tmpBoardTable);
                }
            } while (board.FindFreeField().x != -1);

        }
        /// <summary>
        /// Do all possible moves on of hetman
        /// </summary>
        /// <param name="_cooHetman">Coordinates od hetman</param>
        /// <param name="_tmpBoardTable">Temporary board for hetman and possible moves</param>
        private void DoPossibleMoves(Coordinate _cooHetman, List<List<string>> _tmpBoardTable)
        {
            //moves of hetman at angles
            board.DoPossibleMove(-1, -1, _cooHetman, _tmpBoardTable);
            board.DoPossibleMove(1, 1, _cooHetman, _tmpBoardTable);
            board.DoPossibleMove(-1, 1, _cooHetman, _tmpBoardTable);
            board.DoPossibleMove(1, -1, _cooHetman, _tmpBoardTable);
            //moves of hetman straight
            board.DoPossibleMove(0, -1, _cooHetman, _tmpBoardTable);
            board.DoPossibleMove(0, 1, _cooHetman, _tmpBoardTable);
            board.DoPossibleMove(-1, 0, _cooHetman, _tmpBoardTable);
            board.DoPossibleMove(1, 0, _cooHetman, _tmpBoardTable);
        }
    }
}
